package com.lzdongrui.backend.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.lzdongrui.backend.domain.dto.ApplyLeaveAuditDTO;
import com.lzdongrui.backend.domain.dto.ApplyLeaveDTO;
import com.lzdongrui.backend.domain.vo.ApplyLeaveAuditVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lzdongrui.common.annotation.Log;
import com.lzdongrui.common.core.controller.BaseController;
import com.lzdongrui.common.core.domain.AjaxResult;
import com.lzdongrui.common.enums.BusinessType;
import com.lzdongrui.backend.domain.ApplyLeaveAudit;
import com.lzdongrui.backend.service.IApplyLeaveAuditService;
import com.lzdongrui.common.utils.poi.ExcelUtil;
import com.lzdongrui.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 请假审核Controller
 * 
 * @author wyh
 * @date 2023-05-19
 */
@RestController
@RequestMapping("/backend/auditLeave")
public class ApplyLeaveAuditController extends BaseController
{
    @Autowired
    private IApplyLeaveAuditService applyLeaveAuditService;

    /**
     * 查询请假审核列表
     */
    @PreAuthorize("@ss.hasPermi('backend:auditLeave:list')")
    @GetMapping("/list")
    public TableDataInfo list(ApplyLeaveAuditDTO applyLeaveAuditDTO)
    {
        startPage();
        applyLeaveAuditDTO.setAudit(getUserId());
        List<ApplyLeaveAuditVO> list = applyLeaveAuditService.selectApplyLeaveAuditList(applyLeaveAuditDTO);
        return getDataTable(list);
    }

    /**
     * 获取对应请假申请下的所有审核记录
     */
    @PreAuthorize("@ss.hasPermi('backend:auditLeave:find-list')")
    @GetMapping("/findList")
    public TableDataInfo FindIdGetlist(ApplyLeaveAudit applyLeaveAudit)
    {
        List<ApplyLeaveAudit> list = applyLeaveAuditService.FindIdGetlist(applyLeaveAudit);
        return getDataTable(list);
    }

    /**
     * 导出请假审核列表
     */
    @PreAuthorize("@ss.hasPermi('backend:auditLeave:export')")
    @Log(title = "请假审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ApplyLeaveAuditDTO applyLeaveAuditDTO)
    {
        List<ApplyLeaveAuditVO> list = applyLeaveAuditService.selectApplyLeaveAuditList(applyLeaveAuditDTO);
        ExcelUtil<ApplyLeaveAuditVO> util = new ExcelUtil<ApplyLeaveAuditVO>(ApplyLeaveAuditVO.class);
        util.exportExcel(response, list, "请假审核数据");
    }

    /**
     * 获取请假审核详细信息
     */
    @PreAuthorize("@ss.hasPermi('backend:auditLeave:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(applyLeaveAuditService.selectApplyLeaveAuditById(id));
    }

    /**
     * 新增请假审核
     */
//    @PreAuthorize("@ss.hasPermi('backend:auditLeave:add')")
    @Log(title = "请假审核", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ApplyLeaveAudit applyLeaveAudit,List<MultipartFile> files)
    {
        return toAjax(applyLeaveAuditService.insertApplyLeaveAudit(applyLeaveAudit));
    }


    /**
     * 修改请假审核
     */
    @PreAuthorize("@ss.hasPermi('backend:auditLeave:edit')")
    @Log(title = "请假审核", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ApplyLeaveAudit applyLeaveAudit)
    {
        return toAjax(applyLeaveAuditService.updateApplyLeaveAudit(applyLeaveAudit));
    }


    /**
     * 删除请假审核
     */
    @PreAuthorize("@ss.hasPermi('backend:auditLeave:remove')")
    @Log(title = "请假审核", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(applyLeaveAuditService.deleteApplyLeaveAuditByIds(ids));
    }
}
